<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click = "forceUpdate">强制刷新</button><br/>

        <!-- 添加 删除 修改 不会改变数组地址 vue检测不到不会刷新页面 -->
        <button @click = "arr[0] = '666' ">修改</button>
        <button @click = "arr.length = 2">删除</button>
        <button @click = "arr[4] = '888' ">添加</button>
        <!-- 改变数组地址了 可以重新渲染 -->
        <button @click = "updata">改变数组</button>

        <br/>
        <!-- 使用变更方法可以重新渲染 -->
        <button @click = "add">变更方法改变数组</button>

        <ul>
            <li v-for = "item in arr" key = "Date.now()">
                {{item}}
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false;
        
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    arr:["111" , "222" , "333" , "444"]
                }
            },
            methods:{
                forceUpdate(){
                    this.$forceUpdate()
                },
                updata(){
                    this.arr = this.arr.filter(item => {
                        return item === "222"
                    })
                },
                add(){
                    this.arr.push("100")
                }

            }
        })
    </script>
</body>

</html>